home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.3d26 source
/
tn3270
/
tcpevent.c
< prev
next >
Wrap
Text File
|
1991-05-29
|
7KB
|
277 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.3d21, January 17, 1991
* Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#define __SEG__ 3270tcp
#include "maclib.h"
#include "netevent.h"
#include "hostform.h"
#include "termdef.h"
#include "globals.h"
extern char tcpinitok; /* network code is active */
extern int myport;
extern char pend_conn;
extern struct machinfo * mp;
extern char vmxbgn;
extern char vmxsub;
extern unsigned char * rcvbuff;
extern short rcvmax;
extern char data_init; /* flag for stream parsing */
extern char serverconn; /* flag for line mode server */
extern char servermode; /* server mode active */
extern char hadascii; /* flag for have had ascii data */
char tcpinv; /* tcp pending invldscr */
short rdportnum();
tcpevent()
{
int ev, what, data;
short cnt, i;
char msg[128];
struct machinfo *Slooknum();
OSErr rc, createwindow();
myStask();
ev = Sgetevent(USERCLASS | ERRCLASS | CONCLASS, &what, &data);
if (ev) {
sprintf(msg, "event = %d, class = %d, data = %d", ev, what, data);
putln(msg);
switch(what) {
case CONCLASS:
switch(ev) {
case CONOPEN:
if (pend_conn == 2) {
pend_conn = 3;
online = 1;
rc = createwindow();
if (rc != noErr) {
tcplgout();
}
/* if the session was opened by the api, we
delay registering the session until data
is received. (See telnet.c) */
if (!apiopenpend) {
apiregister(1);
}
if (serverconn) {
servermode = 0;
srvswitch();
if (!logon) {
if (kblock) {
kblock = 0;
newstat();
}
hadascii = 1;
return;
}
}
}
break;
case CONDATA:
if (data != myport) break;
cnt = netread(data, rcvbuff+64, rcvmax);
myStask();
if (cnt == 0) break;
if (cnt < 0) {
closeresponse(closeNetFail);
tcplgout();
break;
}
if (logon) {
wr_active = 1;
newstat();
}
while (cnt > 0) {
telrcv(rcvbuff+64, cnt);
myStask();
cnt = netread(data, rcvbuff+64, rcvmax);
myStask();
}
if (wr_active && (!needwrite)) {
wr_active = 0;
newstat();
}
if (tcpinv && (data_init == 1)) { /* 3270 mode */
tcpinv = 0;
invldscr();
if (pndbeep) {
pndbeep = 0;
myStask(); /* beep takes a while */
beep();
myStask();
}
}
else if (logon == 0) { /* line mode */
if (pndbeep) {
pndbeep = 0;
myStask(); /* beep takes a while */
beep();
myStask();
}
}
if (cnt < 0) {
closeresponse(closeNetFail);
tcplgout();
}
break;
case CONCLOSE:
if (data != myport) break;
closeresponse(closeNetClose);
tcplgout();
break;
case CONFAIL:
if (pend_conn == 2) {
stoperr(conalrt);
pend_conn = 0;
kblcode = 4;
if (apiopen) {
apiopenerr(openConnFailed);
}
}
break;
default:
break;
}
break;
case USERCLASS:
switch(ev) {
case DOMOK:
if ((pend_conn == 1) && (data == myport)) {
mp = Slooknum(data);
if (mp == 0) {
putln("Slooknum failed!");
stoperr(topnalrt);
pend_conn = 0;
kblcode = 4;
if (apiopen) {
apiopenerr(openConnFailed);
}
break;
}
else {
sprintf(msg, "number for %s is %d.%d.%d.%d",
mp->hname, mp->hostip[0], mp->hostip[1],
mp->hostip[2], mp->hostip[3]);
putln(msg);
}
myport = Snetopen(mp, rdportnum());
if (myport < 0) {
putln("Snetopen failed!");
stoperr(topnalrt);
pend_conn = 0;
kblcode = 4;
if (apiopen) {
apiopenerr(openConnFailed);
}
}
else pend_conn = 2;
}
break;
case DOMFAIL:
if ((pend_conn == 1) && (data == myport)) {
stoperr(numalrt);
pend_conn = 0;
kblcode = 4;
if (apiopen) {
apiopenerr(openResFailed);
}
}
break;
case FTPCOPEN:
ftpcopen = 1;
if (myWindow != 0) newstat();
putln("FTP control connection opened");
break;
case FTPCLOSE:
ftpcopen = 0;
if (myWindow != 0) newstat();
putln("FTP control connection closed");
break;
case FTPBEGIN:
ftpdopen = 1;
if (myWindow != 0) newstat();
putln("FTP data connection opened");
break;
case FTPEND:
ftpdopen = ftplopen = 0;
if (myWindow != 0) newstat();
putln("FTP data or list connection closed");
break;
case FTPLIST:
ftplopen = 1;
if (myWindow != 0) newstat();
putln("FTP list connection opened");
break;
case RCPBEGIN:
putln("rcp transfer begin");
break;
case RCPEND:
putln("rcp transfer ended");
break;
default:
break;
}
break;
case ERRCLASS:
NetError(data);
break;
default:
break;
}
myStask();
}
while ((kbqsize > 0) && (!kblock)) {
if (vmxbgn && (!vmxsub)) break;
hndkbd(kbqueue[0].code, kbqueue[0].shift);
kbqsize--;
myStask();
if (kbqsize > 0)
for (i=0; i < kbqsize; i++) {
kbqueue[i].code = kbqueue[i+1].code;
kbqueue[i].shift = kbqueue[i+1].shift;
}
}
}
myStask()
{
if (tcpflg && tcpinitok) {
Stask();
/* if (ftpcopen || ftpdopen || ftplopen)
rftpd(CONOPEN+1); shouldn't need this ? */
}
}